package com.example.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @PackageName:com.example.config
 * @className:MyMvcConfig
 * @Description:
 * @author:朱楚利
 * @date:2021/5/10 23:12
 */
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {


    /***
     * @Description 添加视图跳转
     * @Date 14:00 2021/5/11
     * @author 朱楚利
    */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/main.html").setViewName("dashboard");
    }


    /***
     * @Description 添加拦截器
     * @Date 14:00 2021/5/11
     * @author 朱楚利
    */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**").excludePathPatterns("/index.html","/","/user/login","/css/**","/js/**","/img/**");
    }

    /***
     * @Description 自定义国际化
     * @Date 9:17 2021/5/11
     * @author 朱楚利
    */
    @Bean
    public LocaleResolver localeResolver(){
        return new MyLocaleResolver();
    }

}
